import Vue from "vue";

import VueRouter from "vue-router";

//使用路由懒加载引入组件
const Home = () => import("@pages/Home");  //import方法既可以动态引入组件又可以返回一个promise实例。
const Search = () => import("@pages/Search");
const Login = () => import("@pages/Login");
const Register = () => import("@pages/Register");

Vue.use(VueRouter);

export default new VueRouter({
  mode: "history",
  routes:[
    {
      path: "/home",
      component: Home,
      name: "home",
    },
    {
      path: "/search",
      component: Search,
      name: "search",
    },
    {
      path: "/login",
      component: Login,
      name: "login",
    },
    {
      path: "/register",
      component: Register,
      name: "register",
    },
    {
      path: "/",   //默认路由
      redirect: "/home",
    },
  ]
})